package com.tiniplanet.webgate.web.controller;

import org.apache.log4j.Logger;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tiniplanet.webgate.common.AppConstants;

@Controller
public class LoginController {
	private static final Logger logger = Logger.getLogger(LoginController.class);

	@RequestMapping(method = RequestMethod.GET, value = "login")
	public String setupRegisterForm(ModelMap model) {
		logger.debug("get register form");
		
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth.getName().equals(AppConstants.ANONYMOUS_USER)) {
			return "login";
		}

		return "redirect:home";
	}

	@RequestMapping(method = RequestMethod.GET, value = "/denied")
	public String setupDeniedPage(ModelMap model) {
		return "denied";
	}

	@RequestMapping(method = RequestMethod.GET, value = "/success")
	public String setupSuccessPage(ModelMap model) {
		return "success";
	}

}